package com.rupertjones.globalcron.util;

import org.joda.time.DateTimeZone;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>&copy Rupert Jones 2012</p>
 *
 * @author rup
 */
public class TimeZoneSource {

    public static List<DateTimeZone> getAllTimeZones() {
        List<DateTimeZone> all = new ArrayList<DateTimeZone>();
        for (Object id : DateTimeZone.getAvailableIDs()) {
            try {
              all.add(DateTimeZone.forID((String) id));
            } catch (IllegalArgumentException iae) {
                //ignore
            }
        }
        return all;
    }

    public static DateTimeZone fromId(String id) {
        try {
            return DateTimeZone.forID(id);
        } catch (IllegalArgumentException iae) {
            //ignore
            return null;
        }
    }
}
